/*===========================================================
 
 .---=||||[ B L O O D Y ]|||||=====================----------....
 |                                                              |
 |    THE  M O S T   B L O O D Y  GAME EVER!                    |
 |                                                              |
 |    bloody harvest is coming... soon,                         |
 |                                              heil Satan!     |
 !                                                              !
 .                                                              ,
  ~~~~-------------================================|||||||||==-~




 Name-Space: {core, logic, editor}
 Module: {draw, coll, scgr, ...}
 Class: <name of class>
 Last modification:  <author>, <time>

 TODO:
 <-------- todo #1 ---------->
 <-------- todo #2 ---------->
 <-------- todo #3 ---------->
        ............
 <-------- todo #n ---------->

 FIX:
 <-------- fix #1 ----------->
 <-------- fix #1 ----------->
         ..........
 <-------- fix #n ----------->




 
 
 ============================================================*/
///////////////////////////////////////////////////////////////////////////////
//
// Pop Zombie Game
// 
// Font class header file
// 
///////////////////////////////////////////////////////////////////////////////
#ifndef __Font_header_file
#define __Font_header_file

#include <string>
#include "common.h"
#include "core/draw/Texture.h"
#include "core/vmath.h"

namespace core
{
    namespace draw
    {
	
	/**
	 * This class is used for drawing text to GL device.
	 */
	class Font
	{
	public:
		/**
		 * Standart constructor of font. Loads font from bitmap
		 * and uses text description for locating glyphs inside
		 * bitmap
		 */
		Font(std::string txtFile, std::string textureFileName);
		
		/**
		 * Frees all allocated resources for this font
		 */
		~Font();
	
		/**
		 * Draws text onto screen at position x,y, using color (r,g,b)
		 * @param x X coordinate on screen of text [pixels]
		 * @param y Y coordinate on screen of text [pixels]
		 * @param text Text to be displayed on screen
		 * @param r Red component of text color to be displayed on screen
		 * @param g Green component of text color to be displayed on screen
		 * @param b Blue component of text color to be displayed on screen
		 * @note All charactes of text that do not satisfy condition 
		 * 32 <= ASCII <= 127 will be replaced with question mark.
		 */
		void draw(float x, float y, std::string text, float r, float g, float b) const;
		
		/**
		 * Prints formated text onto screen at position x,y, using color (r,g,b)
		 * @param x X coordinate on screen of text [pixels]
		 * @param y Y coordinate on screen of text [pixels]
		 * @param r Red component of text color to be displayed on screen
		 * @param g Green component of text color to be displayed on screen
		 * @param b Blue component of text color to be displayed on screen
		 * @param fmt Format string same as for printf function
		 * @note All charactes of text that do not satisfy condition 
		 * 32 <= ASCII <= 127 will be replaced with question mark.
		 */
		void printf(float x, float y, float r, float g, float b, const char* fmt, ...) const;
	private:
	
		/**
		 * Loads glyph descrition from text file into array of Glyph structure
		 */
		void loadGlyphs(std::string txtFile);
		
		/**
		 * Builds display list for representing all font glyphs
		 */
		void buildGlyphs();
		
		/**
		 * Structure describing location and size of glyph in bitmap/texture.
		 */
		struct Glyph
		{
			/**
			 * Begining position of glyph in texture 
			 */
			Vector2f p1;
			
			/**
			 * Ending position of glyph in texture 
			 */
			Vector2f p2;
			
			/**
			 * Width and height of glyph [pixels]
			 */
			int w;
			
			/**
			 * Height of glyph [pixels]
			 */
			int h;
		};
		
		/**
		 * Texture of font glyphs
		 */
		Texture& fontTexture;
		
		/**
		 * Base of GL list of each glyph
		 */
		GLuint fontBase;
		
		/**
		 * Description of all glyphs
		 */
		Glyph glyphs[95];
		
	};
	
    }	
}

#endif //__Font_header_file
